<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子12-ES6/7常用语法介绍</title>
    </head>
    <body>
        <pre>
            <code>
                // 例子12

                function add([x, y]) {
                    return x + y;
                }
                add([1, 2]); // 3

                //--------------------------------------------------------------------------

                function move({x = 0, y = 0} = {}) {
                    return [x, y];
                }

                move({x: 3, y: 8}); // [3, 8]
                move({x: 3}); // [3, 0]
                move({}); // [0, 0]
                move(); // [0, 0]

                //--------------------------------------------------------------------------

                function move({x, y} = { x: 0, y: 0 }) {
                    return [x, y];
                }

                move({x: 3, y: 8}); // [3, 8]
                move({x: 3}); // [3, undefined]
                move({}); // [undefined, undefined]
                move(); // [0, 0]

                //--------------------------------------------------------------------------

                [[1, 2], [3, 4]].map(([a, b]) => a + b); // [ 3, 7 ]
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/12.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>